package com.yrd.centerlog;

import org.zeromq.ZMQ;

import com.yrd.common.webui.HttpEngine;

public class ListenEngine {
	String url;
	ZMQ.Context context;
	ZMQ.Socket socket;
	volatile boolean alive;
	Thread thread;
	public ListenEngine(String url) {
		alive=true;
		this.url = url;
		context = ZMQ.context(1);
		socket = context.socket(ZMQ.PULL);
    	
	}
	public void start(){
    	socket.bind(url);
    	thread = new Thread(new Runnable() {
			public void run() {
		    	while(alive){
		    		String msg = socket.recvStr();
		            System.out.println(msg);
		            HttpEngine.getInstance().sendMessage(msg);
		       }
		    	context.close();
			}
		});
    	thread.start();
		System.out.println("ListenEngine 启动");
	}
	public void close(){
		alive=false;
		socket.close();
	}
}
